Radix Sort in Python [on hold]

Posted by Steven Ramsey on Stack Overflow See other posts from Stack Overflow or by Steven Ramsey
Published on 2013-11-05T02:37:53Z Indexed on 2013/11/05 3:54 UTC
Read the original article Hit count: 327

Filed under:
|
|

I could use some help. How would you write a program in python that implements a radix sort?

Here is some info:

A radix sort for base 10 integers is a based on sorting punch cards, but it turns out the sort is very ecient. The sort utilizes a main bin and 10 digit bins. Each bin acts like a queue and maintains its values in the order they arrive. The algorithm begins by placing each number in the main bin. Then it considers the ones digit for each value. The rst value is removed and placed in the digit bin corresponding to the ones digit. For example, 534 is placed in digit bin 4 and 662 is placed in the digit bin 2. Once all the values in the main bin are placed in the corresponding digit bin for ones, the values are collected from bin 0 to bin 9 (in that order) and placed back in the main bin. The process continues with the tens digit, the hundreds, and so on. After the last digit is processed, the main bin contains the values in order. Use randint, found in random, to create random integers from 1 to 100000. Use a list comphrension to create a list of varying sizes (10, 100, 1000, 10000, etc.). To use indexing to access the digits rst convert the integer to a string. For this sort to work, all numbers must have the same number of digits. To zero pad integers with leading zeros, use the string method str.zfill(). Once main bin is sorted, convert the strings back to integers.

I'm not sure how to start this, Any help is appreciated. Thank you.

© Stack Overflow or respective owner

Related posts about python

Related posts about function